package grammatica;

import java.util.ArrayList;

public class Starter {
	private ArrayList<Term> terms;
	
	public Starter(Term term){
		terms = new ArrayList<Term>();
		terms.add(term);
	}
	
	public boolean isNonTerminalStarter(){
		return terms.get(0) instanceof NonTerminal;
	}
	
	public String toString(){
		String s = "";
		if(isNonTerminalStarter()){
			s = "Starters from: " + getFirst().name;
		}
		else{
			for(Term t : terms){
				if(!s.equals(""))s += " ";
				s += t.name;
			}
		}		
		return s;
	}

	public void append(Term t) {
		terms.add(t);
	}

	public Term getFirst() {
		return terms.get(0);
	}
	
	public boolean equals(Object o){
		if(!( o instanceof Starter))return false;
		Starter s = (Starter)o;
		if(terms.size() != s.terms.size())return false;
		for(int i = 0; i < terms.size(); i++){
			if(!terms.get(i).equals(s.terms.get(i)))return false;
		}
		return true;
	}

	public boolean compareSet(ArrayList<Term> set) {
		if(terms.size() != set.size())return false;
		for(int i = 0; i < set.size(); i ++){
			if(!terms.get(i).equals(set.get(i)))return false;
		}
		return true;
	}
}
